<?php

namespace app\admin\controller\system;

use app\admin\service\system\AminService;
use app\admin\service\system\MenuService;
use app\Request;
use app\BaseController;

class User extends BaseController
{
    /**
     * 获取用户列表
     * @author dgc<453342213@qq.com>
     */
    public function index()
    {
        try {
            $service = new AminService();
            $res = $service->getList([]);
            returnDate($res);
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }


    public function getMyInfo(Request $request)
    {
        $userInfo = $request->userInfo;
        $userInfo['menu_list'] = (new MenuService())->menuArr($userInfo);
        returnDate($userInfo);
    }

    /**
     * 操作
     * @param Request $request
     * @throws \Exception
     * @author dgc<453342213@qq.com>
     */
    public function saves(Request $request)
    {
        try {
            $param = $this->checkParam(['component', 'icon', 'is_cache', 'is_hidden', 'name', 'path', 'pid', 'redirect', 'sort', 'status'], false);
            $res = (new MenuService())->saves($param, $request->param('id', 0));
            returnDate($res);
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }
}
